#########################
#Creation dataset for Rproxy

df_half <- data.frame(R0_provinces_half1$Area)
df_half$R0_mean_half1 <- R0_provinces_half1$mean
df_half$R0_mean_half2 <- R0_provinces_half2$mean

colnames(df_half)[1] <- "Area"

############################################
#Importation weather data

meteoA <- read.table("Data/humidity_data_2020mar02.csv",sep=",",header=T)

colnames(meteoA)

meteoA_for_provinces <- meteoA[,-c(1,2,4,5,6,7)]

colnames(meteoA_for_provinces)

meteoA_for_provinces <- meteoA_for_provinces[,c("prov_en","t2m_jan20_1st16","t2m_jan20_2nd15","t2m_feb20_1st15","rhov_jan20_2nd15","rhov_feb20_1st15")]

meteoA_for_provinces_mean <- aggregate(meteoA_for_provinces[,2:6], list(meteoA_for_provinces$prov_en), mean)

colnames(meteoA_for_provinces_mean)[1] <- "Area"

df_half <- merge(df_half,meteoA_for_provinces_mean,all.x=T)

colnames(df_half)
############################
#Importation mobility data

data_mobility <- read.table("Data/wuhan_out_agg.csv", header=T, sep=",")

data_mobility_for_model <- data.frame(data_mobility$Province,rowMeans(data_mobility[2:nrow(data_mobility)]))

colnames(data_mobility_for_model) <- c("Area","Mobility")

df_half <- merge(df_half,data_mobility_for_model,all.x=T)

############################
#Steps of filtering

index1 <- which(is.na(df_half$R0_mean_half2))
df_half[index1,]

index2 <- which(is.na(df_half$Mobility))
df_half[index2,]

index4 <- which(df_half$R0_mean_half2>2.5)
df_half[index4,]

index5 <- which(df_half$R0_mean_half1>2.5)
df_half[index5,]

selection1 <- df_half[-sort(unique(c(index1))),]
selection2 <- df_half[-sort(unique(c(index1,index2))),]
selection3 <- df_half[-sort(unique(c(index1,index2,index4,index5))),]

############################

#Models with mobility

mod_mobility <- lm(R0_mean_half1~Mobility, data=selection2[-13,])
summary(mod_mobility)

mod_mobility2 <- lm(R0_mean_half1~Mobility, data=selection3)
summary(mod_mobility2)

############################

#Models with temperature

mod_temperature <- lm(log(R0_mean_half1)~t2m_jan20_2nd15, data=selection1)
summary(mod_temperature)

mod_temperature2 <- lm(log(R0_mean_half1)~t2m_jan20_2nd15, data=selection2)
summary(mod_temperature2)

mod_temperature3 <- lm(log(R0_mean_half1)~t2m_jan20_2nd15, data=selection3)
summary(mod_temperature3)

mod_temperature <- lm(log(R0_mean_half2)~t2m_feb20_1st15, data=selection1)
summary(mod_temperature)

mod_temperature2 <- lm(log(R0_mean_half2)~t2m_feb20_1st15, data=selection2)
summary(mod_temperature2)

mod_temperature3 <- lm(log(R0_mean_half2)~t2m_feb20_1st15, data=selection3)
summary(mod_temperature3)

#############################

#Models with humidity

mod_humidity <- lm(log(R0_mean_half1)~rhov_jan20_2nd15, data=selection1)
summary(mod_humidity)

mod_humidity2 <- lm(log(R0_mean_half1)~rhov_jan20_2nd15, data=selection2)
summary(mod_humidity2)

mod_humidity3 <- lm(log(R0_mean_half1)~rhov_jan20_2nd15, data=selection3)
summary(mod_humidity3)

mod_humidity <- lm(log(R0_mean_half2)~rhov_feb20_1st15, data=selection1)
summary(mod_humidity)

mod_humidity2 <- lm(log(R0_mean_half2)~rhov_feb20_1st15, data=selection2)
summary(mod_humidity2)

mod_humidity3 <- lm(log(R0_mean_half2)~rhov_feb20_1st15, data=selection3)
summary(mod_humidity3)
